#! /bin/bash

NDK_ROOT=$HOME/android-ndk/android-ndk-r14b
PREBUILT=$NDK_ROOT/toolchains/x86_64-4.9/prebuilt/linux-x86_64
PLATFORM=$NDK_ROOT/platforms/android-21/arch-x86_64

export LDFLAGS="-L$PLATFORM/usr/lib -L$PREBUILT/x86_64-linux-android/lib "
export CFLAGS="-I$PLATFORM/usr/include --sysroot=${PLATFORM} -O2"

export CPPFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="$LDFLAGS"

export AS=$PREBUILT/bin/x86_64-linux-android-as
export LD=$PREBUILT/bin/x86_64-linux-android-ld
export CXX="$PREBUILT/bin/x86_64-linux-android-g++"
export CC="$PREBUILT/bin/x86_64-linux-android-gcc"
export NM=$PREBUILT/bin/x86_64-linux-android-nm
export STRIP=$PREBUILT/bin/x86_64-linux-android-strip
export RANLIB=$PREBUILT/bin/x86_64-linux-android-ranlib
export AR=$PREBUILT/bin/x86_64-linux-android-ar

./configure --host=x86_64-linux \
--prefix=`pwd`/build_out/x264/x86_64 \
--enable-static \
--enable-pic \
--enable-strip \
--disable-cli \
--disable-asm \
--extra-cflags="" \
--cross-prefix=$PREBUILT/bin/x86_64-linux-android- \
--sysroot=$PLATFORM

make clean
make -j8
make install
